package logic

import (
	"context"
	"rent/model/redis"

	"rent/rentrpc/internal/svc"
	"rent/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectlistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectlistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectlistLogic {
	return &CollectlistLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectlistLogic) Collectlist(in *rentrpc.CollectlistRequest) (*rentrpc.CollectlistResponse, error) {
	// todo: add your logic here and delete this line

	scores := redis.Client.ZRevRangeWithScores("collect", 0, 9)

	var Collectsruct []*rentrpc.CollectlistStruct

	for _, list := range scores.Val() {
		str := rentrpc.CollectlistStruct{
			Produce: list.Member.(string),
			UserId:  int64(list.Score),
		}
		Collectsruct = append(Collectsruct, &str)
	}

	return &rentrpc.CollectlistResponse{Lists: Collectsruct}, nil
}
